package com.bishe.serivce.Impl;

import cn.hutool.core.util.StrUtil;
import com.bishe.dao.ApplyDao;
import com.bishe.pojo.Apply;
import com.bishe.pojo.QueryModel;
import com.bishe.serivce.IApplyService;
import com.bishe.utils.JobUtil;
import com.bishe.utils.SqlQueryUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 申请接口实现
 * @date 2022/03/20 41:08:41
 */
@Service
public class ApplyServiceImpl implements IApplyService {
    @Autowired
    private ApplyDao applyDao;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Apply> findAll() {
        return applyDao.findAll();
    }

    @Override
    public Apply findById(String id) {
        return applyDao.findById(id);
    }

    @Override
    public void deleteById(String id) {
        applyDao.deleteById(id);
    }

    @Override
    public void updateById(Apply apply) {
        applyDao.updateById(apply);
    }

    @Override
    public void save(Apply apply) {
        applyDao.save(apply);
    }

    @Override
    public void addOrUpdate(Apply apply, HttpServletRequest httpServletRequest) {
        //保存
        if (StrUtil.isEmpty(apply.getId())|| findById(apply.getId()) == null){
            apply.setId(StrUtil.uuid());
            apply.setCreateTime(new Date());
            apply.setCreateBy(JobUtil.getUserId(httpServletRequest));
            save(apply);
            return;
        }
        //修改
        updateById(apply);
    }

}